YZYZ.Admin.Scenic.newWin 	= null;
YZYZ.Admin.Scenic.newForm 	= null;
YZYZ.Admin.Scenic.levelCB	= null;
YZYZ.Admin.Scenic.newRecord = Ext.data.Record.create([
	{ name: 'id', type: 'string'},
	{ name: 'name', type: 'string'},
	{ name: 'available', type: 'boolean'},
	{ name: 'level', type: 'int'}
]);
YZYZ.Admin.Scenic.showNewWin=function(){
	if(!YZYZ.Admin.Scenic.newWin){
		YZYZ.Admin.Scenic.levelCB=new Ext.form.ComboBox({  
	         id: 'addLevel', 
	         name:'addLevel', 
	         allowBlank: false,  
	         fieldLabel: "显示级别",  
	         hiddenName: 'hidaddLevel',  
	         displayField: 'name',  
	         valueField: 'id',  
	         typeAhead: true,  
	         triggerAction: 'all',  
	         store: YZYZ.levelData.levelStore,  
	         mode: 'local',
	         width:300 ,
	         editable:false
 		});
		YZYZ.Admin.Scenic.newForm = new Ext.form.FormPanel({
			labelWidth:100,
			autoScroll:true,
			width:650,
			height:400,
			region:'center',
			labelAlign:'right',
			bodyStyle:'padding-top:10px',
			items:[{
				fieldLabel:'名称',
				xtype:'textfield',
				width:300,
				maxLength:20,
				id:'addName'	
			},{
				fieldLabel:'地址',
				xtype:'textfield',
				width:300,
				maxLength:40,
				id:'addLocation'	
			},YZYZ.Admin.Scenic.levelCB,
			YZYZ.Admin.Scenic.groupCB,
			{
				xtype:'htmleditor',
				width:550,
				height:400,
				fieldLabel:'景区描述',
				id:'addDescription'
				
			}]
		});
		YZYZ.Admin.Scenic.newWin = new Ext.Window({
			title:'添加景区',
			width:700,
			height:400,
			layout:'border',
			closable:true,
			closeAction:'hide',
			modal:true,
			items:[YZYZ.Admin.Scenic.newForm],
			buttons:[{
				text:'提交',
				width:60,
				handler:YZYZ.Admin.Scenic.addSubmit
			},{
				text:'取消',
				width:60,
				handler:function(){YZYZ.Admin.Scenic.newWin.hide()}
			}]
		});
	}
	YZYZ.Admin.Scenic.newWin.show();
};
YZYZ.Admin.Scenic.addSubmit = function(){
	var name 		= Ext.getCmp("addName").getValue();
	var location	= Ext.getCmp("addLocation").getValue();
	var level		= Ext.getCmp("addLevel").getValue();
	var description = Ext.getCmp("addDescription").getValue();
	var ownerId 	= Ext.getCmp("addRegion").getValue();
	if(Ext.isEmpty(name)){
		YZYZ.Curtain.alert("请填写名称");
		Ext.getCmp("addName").markInvalid();
		return;
	}
	if(name.length > 20){
		YZYZ.Curtain.alert("名称长度应小于20");
		Ext.getCmp("addName").markInvalid();
		return;
	}
	if(Ext.isEmpty(location)){
		YZYZ.Curtain.alert("请填写地址");
		Ext.getCmp("addLocation").markInvalid();
		return;
	}
	if(name.length > 40){
		YZYZ.Curtain.alert("地址长度应小于40");
		Ext.getCmp("addLocation").markInvalid();
		return;
	}
	if(Ext.isEmpty(ownerId)){
		YZYZ.Curtain.alert("请选择分组");
		Ext.getCmp("addRegion").markInvalid();
		return;
	}
	if(Ext.isEmpty(description)){
		YZYZ.Curtain.alert("请填写描述");
		Ext.getCmp("addDescription").markInvalid();
		return;
	}
	if(description.length > 50000){
		YZYZ.Curtain.alert("描述长度应小于50000");
		Ext.getCmp("addDescription").markInvalid();
		return;
	}
	YZYZ.Curtain.msg("系统处理中....");
	Ext.Ajax.request( {
		url		: Ext.get("addUrl").dom.value,
		timeout	: 30000,
		method	: 'POST',
		params	: {
			name 		:  name,
			description	: description,
			location    : location,
			level		: level,
			ownerId 	: ownerId
		},
		success : function(result, request) {
			result = Ext.util.JSON.decode(result.responseText);
			if(result.code == YZYZ.success){
				var rec = new YZYZ.Admin.Scenic.newRecord({
					name 		:  name,
					location    : location,
					level		: level,
					available 	: true,
					id 			: result.id
					
				});
				YZYZ.Curtain.msg("添加成功");
				YZYZ.Admin.Scenic.grid.getStore().insert(0, rec);
				YZYZ.Admin.Scenic.newWin.hide();			
			}
			else {
				YZYZ.Curtain.alert(result.message);
			}
		},
		failure : function(result, request) {
			YZYZ.Curtain.alert("操作失败！程序错误或网络故障");
		}
	});	
	
};